package 代码记录.指定公司代码练习记录.华为_2024.分值200;

import java.util.Scanner;

/**
 * @author zx
 * @create 2024-02-16 14:49
 * 看懂人家的思路了；简单题
 */
public class 贪吃的猴子_39 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] numbers = new int[n];
        for (int i = 0; i < n; i++) {
            numbers[i] = sc.nextInt();
        }
        int N = sc.nextInt();
        int leftSum = 0;
        // 初始化左边选N个，右侧选0个的情况
        for (int i = 0; i < N; i++) {
            leftSum += numbers[i];
        }
        int res = leftSum;
        // 使用双指针调整左右两边的元素选取个数
        for (int left = N - 1, right = numbers.length - 1; left >= 0; left--, right--) {
            leftSum = leftSum + numbers[right] - numbers[left];
            res = Math.max(res, leftSum);
        }
        System.out.println(res);
    }
}
